<?php

namespace addons\venue\controller;

use app\admin\model\venue\app\Url;
use app\common\controller\Api;
use app\admin\model\venue\rotation\Rotation as Rt;
use think\Request;

class Rotation extends Api
{

    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['list'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    protected $config = "";

    public function __construct(Request $request = null)
    {
        $this->config = get_addon_config("venue");
        parent::__construct($request);
    }

    /*
     * 获取轮播图列表
     */
    public function list()
    {
        $type   = $this->request->post('type')??1;    // 类型:1=首页,2=其他
        $position   = $this->request->post('position')??1;    // 位置
        $count  = $this->request->post('count')??10;    // 返回数量
        $where = [];

        $where['type'] = ["=",$type];
        $where['position'] = ["=",$position];

        $data = Rt::where("state",1)->where($where)->order("weigh","desc")->limit($count)->select()
            ->each(function ($item){
                $item->url = Url::where("id",$item->url)->value('url');
                $item->image = cdnurl($item->image,true);
            });;
        $this->success('返回成功',$data);
    }

}
